from openpyxl import Workbook
from openpyxl.cell import Cell

wb = Workbook()
sheet = wb.active

for row in sheet['A1:F10']:
    for cell in row:
        cell.value = '单元格单元格单元格单元格单元格单元格单元格'

############################1.单元格的宽和高########################

# 第一行的  高度 80磅
sheet.row_dimensions[1].height = 80

# 第三列的  宽度 100磅
sheet.column_dimensions['C'].width = 100

############################2.单元格内字体、字号等信息########################
cell: Cell = sheet['C5']
from openpyxl.styles import Font

cell.font = Font(
    name="楷体",  # 字体
    color="00FF00",  # 字体颜色,
    size=40,  # 字体大小
    bold=False,  # 是否加粗
    underline='single',  # 下划线
    strike=True,  # 删除线
)

#########################3..换行、单元格内对齐方式###########################
from openpyxl.styles import Alignment

cell.alignment = Alignment(
    wrap_text=True,  # 文字特别多的时候 是否 换行
    horizontal='left',  # 水平居中
    vertical='bottom',  # 垂直 居中 top  center bottom
)

##########################4.单元格颜色##########################
from openpyxl.styles import PatternFill

cell.fill = PatternFill(
    fill_type='solid',
    fgColor='FF0000'

)

############################5.边框线的形式和颜色########################
from openpyxl.styles import Border, Side

cell.border = Border(
    left=Side(border_style='dashed', color='00F000'),
    right=Side(border_style='thick', color='FFF000'),
    top=Side(border_style='double', color='0FF0FF'),
    bottom=Side(border_style='dotted', color='00FFFF')
)

wb.save('03celluse.xlsx')

print('单元格的样式操作....')
